﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KerriganDirection.DirectionServiceWCF;

namespace KerriganDirection.Helpers
{
    public static class HelperMethods
    {
        public enum UnitDurationEnum
        {
            Hour = 1,
            Day = 7,
            Week = 35,
        }

        public static int GetTimeUnit(UnitDurationEnum unitType)
        {
            int res = 0;

            switch (unitType)
            {
                case UnitDurationEnum.Day :
                    res = int.Parse(UnitDurationEnum.Day.ToString());
                    break;
                case UnitDurationEnum.Hour:
                    res = int.Parse(UnitDurationEnum.Hour.ToString());
                    break;
                case UnitDurationEnum.Week:
                    res = int.Parse(UnitDurationEnum.Week.ToString());
                    break;
            }

            return res;
        }

        public static DateTime GetEndDate(SessionDC dc)
        {
            DateTime res = new DateTime();
            int duration = dc.Formation.Duration;
            int unitDuration = dc.Formation.UnitDuration;
            int hours = dc.Date.Hour;
            DateTime old = dc.Date;

            try
            {
                if (unitDuration == 1)
                {
                    //Si Formation est une formation scooter et que la duree va depaser la journee de travail
                    if (dc.Formation.FormationCategory.IdFormationCategory == 1 && hours >= 15)
                    {
                        hours = hours - ((hours + 3) - 17);
                        dc.Date = new DateTime(old.Year, old.Month, old.Day, hours, 0, 0);
                    }
                    res = new DateTime(dc.Date.Year, dc.Date.Month, dc.Date.Day, hours + duration, 0, 0);
                }
                else if (unitDuration == 2)
                {   
                    dc.Date = new DateTime(old.Year, old.Month, old.Day, 9, 0, 0);
                    res = new DateTime(dc.Date.Year, dc.Date.Month, dc.Date.Day, 17, 0, 0);
                }
                else if (unitDuration == 3)
                {
                    dc.Date = new DateTime(old.Year, old.Month, old.Day, 9, 0, 0);
                    res = new DateTime(dc.Date.Year, dc.Date.Month, (dc.Date.Day + 7) * duration, 17, 0, 0);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return res;
        }
    }
}
